package day_2022_9_to_12.Day;

import java.util.Arrays;

/**
 * @author haomin
 * @date 2022/09/16 21:35
 **/
public class Day14_3_Num581_FindUnsortedSubarray {
    class Solution {
        public int findUnsortedSubarray(int[] nums) {
            int[] arr = nums.clone();
            Arrays.sort(arr);
            int l = 0, r = nums.length-1;
            while(l < nums.length && arr[l] == nums[l]) l++;
            while(r >= 0 && arr[r] == nums[r]) r--;
            if(r == -1) return 0;
            return r-l+1;
        }
    }
}